package mzt;

import java.util.concurrent.TimeUnit;

import org.jsoup.Jsoup;
import org.jsoup.select.Elements;

public class DownLoadPicTread implements Runnable {
	private String url;
	Page page = null;

	public DownLoadPicTread(String url) {
		super();
		this.url = url;
		page = new Page(url);
	}

	@Override
	public void run() {
		for (int i = 1; i <= page.getNum(); i++) {
			url = page.getHref() + "/" + i;

			String body = Utils.connReturnBody(url);
			Elements picDetailCls = Jsoup.parse(body).getElementsByClass(Constant.PAGE_DETAIL_URL_CLASS);
			String attr = Jsoup.parse(picDetailCls.toString()).getElementsByTag("img").attr("src");
			try {
				TimeUnit.SECONDS.sleep(3);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			new Thread(new DownThread(attr, Constant.SAVE_FILE + page.getHref().substring(page.getHref().lastIndexOf("/")))).start();
		}
	}
}
